package com.ftg.learn.chapter08.pattern.myreflech.test01;

/**
 * 一个用来管理和实例化类的工厂模式
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/8/8 14:29
 */

public class BeanFactory {
    /**
     @param beans 用来存储大量待实例化的类信息
     */
    public static BeanResult[] getAllInstance(BeanInfo[] beans) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        BeanResult[] results = new BeanResult[beans.length];
        int index = 0;
        for (BeanInfo bean : beans) {
            Class<?> classBean =  Class.forName(bean.getBeanPath());
            results[index].setBeanName(bean.getBeanName());
            results[index++] = (BeanResult) classBean.newInstance();
        }
        return results;
    }
}
